#-*-coding:utf-8-*-
'''
Created on 2010-7-14

@author: zhaoyh
'''
import config
def CreateTree(model,folderLinks='true'):
    '''
    model 模型
    folderLinks 非末级节点链接是否有效
            产生树
    #                     tree.add(id,pid,name,url,title,target,icon,iconOpen,open); 
    #                     id        ：节点自身的id 
    #                     pid       ：节点的父节点的id 
    #                     name      ：节点显示在页面上的名称 
    #                     url       ：节点的链接地址 
    #                     title     ：鼠标放在节点上所出现的提示信息 
    #                     target    ：节点链接所打开的目标frame（如框架目标 mainFrame或是_blank,_self之类） 
    #                     icon      ：节点关闭时的显示图片的路径 
    #                     iconOpen  ：节点打开时的显示图片的路径 
    #                     open      ：布尔型，节点是否打开（默认为false） 
         tree = new dTree('tree');//创建一个对象.  
         tree.add("1","-1","扩展","/temp","扩展","navtab","","","");
         document.write(tree); 
    '''
    html='<div class="dtree">\n<script type=\"text/javascript\">\n d = new dTree(\'d\');\n   d.config.folderLinks=%s; \n' %folderLinks
    #设置属性
    dbtree=config.db.select(model,what='menu_id,menu_name,menu_url,parent_id,target',where='is_visiblity=0' )
    #tree.add(id,pid,name,url,title,target,icon,iconOpen,open);
    icon=''
    iconOpen=''
    open=''
    html+='d.add("0","-1","","","","","","",""); \n'
    for m in dbtree:        
        id=m.menu_id
        pid=m.parent_id
        name=m.menu_name
        url=m.menu_url
        title=m.menu_name
        target=m.target
        html+='d.add("%s","%s","%s","%s","%s","%s","%s","%s","%s");\n' %(id,pid,name,url,title,target,icon,iconOpen,open)
    html+='document.write(d);\n </script>\n </div>\n'
    return html
